﻿using Capstone.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Capstone.Properties;
using Xamarin.Forms;

namespace Capstone.Services
{
    public class DiaryDataStore : DiaryIDataStore<Item>
    {
        readonly List<Item> diary_items;
        string[] fillList = new string[] { Resources.GutSymptom1 };
        string[] emptyList = new string[] { };
        public DatePicker date = new DatePicker();
        public DiaryDataStore()
        {


            diary_items = new List<Item>()
            {
                new Item {Id = "Gut_Symptom_Diary", Text = Resources.Gut, Description=Resources.GutMessage, Frequency = Resources.GutFreq3, Length = 7, Symptoms = fillList, OtherSymptoms = emptyList, SleepSymptoms = emptyList, startDate = date },
                new Item {Id = "Stool_Quality_Diary", Text = Resources.Stool, Description=Resources.StoolMessage, startDate = date},
            };
        }




        public async Task<bool> AddDiaryItemAsync(Item item)
        {
            diary_items.Add(item);

            return await Task.FromResult(true);
        }

        public async Task<bool> UpdateDiaryItemAsync(Item item)
        {
            var oldItem = diary_items.Where((Item arg) => arg.Id == item.Id).FirstOrDefault();
            diary_items.Remove(oldItem);
            diary_items.Add(item);

            return await Task.FromResult(true);
        }

        public async Task<bool> DeleteDiaryItemAsync(string id)
        {
            var oldItem = diary_items.Where((Item arg) => arg.Id == id).FirstOrDefault();
            diary_items.Remove(oldItem);

            return await Task.FromResult(true);
        }

        public async Task<Item> GetDiaryItemAsync(string id)
        {
            return await Task.FromResult(diary_items.FirstOrDefault(s => s.Id == id));
        }

        public async Task<IEnumerable<Item>> GetDiaryItemsAsync(bool forceRefresh = false)
        {
            return await Task.FromResult(diary_items);
        }
    }
}